
 


 
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <link rel="icon" type="image/vnd.microsoft.icon" href="http://www.gstatic.com/codesite/ph/images/phosting.ico">
 
 <script type="text/javascript">
 
 
 
 var codesite_token = "55b122417e72b952b1b3411d91b5d902";
 
 
 var logged_in_user_email = "efhennum@gmail.com";
 
 
 var relative_base_url = "";
 
 </script>
 
 
 <title>Compilation - 
 xspec -
 
 How are the tests compiled? - Project Hosting on Google Code</title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
 
 <meta name="ROBOTS" content="NOARCHIVE">
 
 <link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/14756227129406843427/css/ph_core.css">
 
 <link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/14756227129406843427/css/ph_detail.css" >
 
 
 
 <link type="application/atom+xml" rel="alternate" href="/feeds/p/xspec/svnchanges/basic?path=/wiki/Compilation.wiki">
 
 
<!--[if IE]>
 <link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/14756227129406843427/css/d_ie.css" >
<![endif]-->
 <style type="text/css">
 .menuIcon.off { background: no-repeat url(http://www.gstatic.com/codesite/ph/images/dropdown_sprite.gif) 0 -42px }
 .menuIcon.on { background: no-repeat url(http://www.gstatic.com/codesite/ph/images/dropdown_sprite.gif) 0 -28px }
 .menuIcon.down { background: no-repeat url(http://www.gstatic.com/codesite/ph/images/dropdown_sprite.gif) 0 0; }
 </style>
</head>
<body class="t6">
 <script type="text/javascript">
 var _gaq = _gaq || [];
 _gaq.push(
 ['siteTracker._setAccount', 'UA-18071-1'],
 ['siteTracker._trackPageview']);
 
 _gaq.push(
 ['projectTracker._setAccount', 'UA-5548232-1'],
 ['projectTracker._trackPageview']);
 
 (function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
 })();
 </script>
 <div id="gaia">
 
 <span>
 
 
 <b>efhennum@gmail.com</b>
 
 
 | <a href="/u/efhennum/" id="projects-dropdown" onclick="return false;"
 ><u>My favorites</u> <small>&#9660;</small></a>
 | <a href="/u/efhennum/" onclick="_CS_click('/gb/ph/profile');" 
 title="Profile, Updates, and Settings"
 ><u>Profile</u></a>
 | <a href="https://www.google.com/accounts/Logout?continue=http%3A%2F%2Fcode.google.com%2Fp%2Fxspec%2Fwiki%2FCompilation" 
 onclick="_CS_click('/gb/ph/signout');"
 ><u>Sign out</u></a>
 
 </span>

 </div>
 <div class="gbh" style="left: 0pt;"></div>
 <div class="gbh" style="right: 0pt;"></div>
 
 
 <div style="height: 1px"></div>
<!--[if IE 6]>
<div style="text-align:center;">
Support browsers that contribute to open source, try <a href="http://www.firefox.com">Firefox</a> or <a href="http://www.google.com/chrome">Google Chrome</a>.
</div>
<![endif]-->




 <table style="padding:0px; margin: 20px 0px 0px 0px; width:100%" cellpadding="0" cellspacing="0">
 <tr style="height: 58px;">
 
 <td style="width: 55px; text-align:center;">
 <a href="/p/xspec/">
 
 <img src="http://www.gstatic.com/codesite/ph/images/defaultlogo.png" alt="Logo">
 
 </a>
 </td>
 
 <td style="padding-left: 0.5em">
 
 <div id="pname" style="margin: 0px 0px -3px 0px">
 <a href="/p/xspec/" style="text-decoration:none; color:#000">xspec</a>
 
 </div>
 <div id="psum">
 <i><a id="project_summary_link" href="/p/xspec/" style="text-decoration:none; color:#000">BDD framework for XSLT</a></i>
 </div>
 
 </td>
 <td style="white-space:nowrap;text-align:right">
 
 <form action="/hosting/search">
 <input size="30" name="q" value="">
 <input type="submit" name="projectsearch" value="Search projects" >
 </form>
 
 </tr>
 </table>


 
<table id="mt" cellspacing="0" cellpadding="0" width="100%" border="0">
 <tr>
 <th onclick="if (!cancelBubble) _go('/p/xspec/');">
 <div class="tab inactive">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner">
 <a onclick="cancelBubble=true;" href="/p/xspec/">Project&nbsp;Home</a>
 </div>
 </div>
 </th><td>&nbsp;&nbsp;</td>
 
 
 
 
 <th onclick="if (!cancelBubble) _go('/p/xspec/downloads/list');">
 <div class="tab inactive">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner">
 <a onclick="cancelBubble=true;" href="/p/xspec/downloads/list">Downloads</a>
 </div>
 </div>
 </th><td>&nbsp;&nbsp;</td>
 
 
 
 
 
 <th onclick="if (!cancelBubble) _go('/p/xspec/w/list');">
 <div class="tab active">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner">
 <a onclick="cancelBubble=true;" href="/p/xspec/w/list">Wiki</a>
 </div>
 </div>
 </th><td>&nbsp;&nbsp;</td>
 
 
 
 
 
 <th onclick="if (!cancelBubble) _go('/p/xspec/issues/list');">
 <div class="tab inactive">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner">
 <a onclick="cancelBubble=true;" href="/p/xspec/issues/list">Issues</a>
 </div>
 </div>
 </th><td>&nbsp;&nbsp;</td>
 
 
 
 
 
 <th onclick="if (!cancelBubble) _go('/p/xspec/source/checkout');">
 <div class="tab inactive">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner">
 <a onclick="cancelBubble=true;" href="/p/xspec/source/checkout">Source</a>
 </div>
 </div>
 </th><td>&nbsp;&nbsp;</td>
 
 
 <td width="100%">&nbsp;</td>
 </tr>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0" class="st">
 <tr>
 
 
 
 <td>
 <div class="issueDetail">
<div class="isf">
 
 <span class="inIssueList"> 
 <span>Search</span>
 <form action="/p/xspec/w/list" method="GET" style="display:inline">
 <select id="can" name="can" style="font-size:92%">
 <option disabled="disabled">Search within:</option>
 
 <option value="1" >&nbsp;All wiki pages</option>
 <option value="3" >&nbsp;Featured pages</option>
 <option value="2" selected="selected">&nbsp;Current pages</option>
 
 
 <option value="5" {is can "5"}selected="selected"{end}>&nbsp;My starred pages</option>
 
 <option value="4" >&nbsp;Deprecated pages</option>
 
 </select>
 <span>for</span>
 <span id="qq"><input type="text" size="38" id="searchq" name="q" value=""
 autocomplete="off" style="font-size:92%" ></span>
 
 
 <input type="submit" value="Search" style="font-size:92%" >
 </form>
 </span>

 
 
 
 
 
 
 

</div>
</div>

 </td>
 
 
 
 
 
 
 <td height="4" align="right" valign="top" class="bevel-right">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 </td>
 </tr>
</table>
<script type="text/javascript">
 var cancelBubble = false;
 function _go(url) { document.location = url; }
</script>


<div id="maincol"
 
>

 
<!-- IE -->







 <style type="text/css">
 .artifactcomment {
 margin: .5em 0 0 0;
 padding: .3em 0 .3em .3em;
 border-top: 3px solid #c3d9ff;
 }
 #commentlist {
 border-bottom: 3px solid #c3d9ff;
 }
 #commentform { padding-top: 1em; }
 .delcom { background: #e8e8e8 }
 .commentcontent { margin: 1em 0;}
 </style>


 <div id="wikicontent">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
 
 <td class="vt" id="wikimaincol" width="100%">
 
 <div style="float:right; width:18em" id="wikimeta">
 <div class="pmeta_bubble_bg">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner">
 <table style="padding: 5px">
 <tr><td colspan="2" style="padding-bottom:5px">Updated <span title="Mon Mar  8 10:00:34 2010">Mar 08, 2010</span>
 
 by <a style="white-space: nowrap" href="/u/jsulak/">jsulak</a>
 </td></tr>
 
 <tr><th class="vt">Labels:</th>
 <td>
 
 <a href="/p/xspec/w/list?q=label:Phase-Implementation"
 title="Developers&#39; guide"
 >Phase-Implementation</a>, 
 
 <a href="/p/xspec/w/list?q=label:Featured"
 title="Listed on project home page"
 >Featured</a>
 
 </td>
 </tr>
 
 
 </table>
 </div>
 <div class="round1"></div>
 <div class="round2"></div>
 <div class="round4"></div>
 </div>
 </div>
 
 <div id="wikiheader" style="margin-bottom:1em">
 
 <img width="15" height="15" id="star_img"
 src="http://www.gstatic.com/codesite/ph/images/star_off.gif"
 style="cursor:pointer"
 
 onclick="_CS_toggleStar(this,
 '',
 {'scope': 'wiki',
 'user': '_CURRENT_USER',
 'item': 'xspec:Compilation',
 'token': codesite_token
 });"/>
 
 &nbsp;
 <span style="font-size:120%;font-weight:bold">Compilation</span>
 &nbsp;
 
 
 <div style="font-style:italic; margin-top: 3px">How are the tests compiled?</div>
 
 </div>
 <h1><a name="Contents"/>Contents<a href="#Contents" class="section_anchor">&para;</a></h1><p><ul><li><a href="#Contents">Contents</a></li><li><a href="#Introduction">Introduction</a></li><li><a href="#Simple_suite">Simple suite</a></li><ul><li><a href="#Test_suite">Test suite</a></li><li><a href="#Stylesheet">Stylesheet</a></li><li><a href="#Query">Query</a></li></ul><li><a href="#Simple_scenario">Simple scenario</a></li><ul><li><a href="#Test_suite">Test suite</a></li><li><a href="#Stylesheet">Stylesheet</a></li><li><a href="#Query">Query</a></li></ul><li><a href="#SUT">SUT</a></li><ul><li><a href="#Test_suite">Test suite</a></li><li><a href="#Stylesheet">Stylesheet</a></li><li><a href="#Query">Query</a></li></ul><li><a href="#Variables">Variables</a></li><ul><li><a href="#Test_suite">Test suite</a></li><li><a href="#Stylesheet">Stylesheet</a></li><li><a href="#Query">Query</a></li></ul><li><a href="#Variable_value">Variable value</a></li><ul><li><a href="#Test_suite">Test suite</a></li><li><a href="#Stylesheet">Stylesheet</a></li><li><a href="#Query">Query</a></li></ul><li><a href="#Variables_scope">Variables scope</a></li><ul><li><a href="#Test_suite">Test suite</a></li><li><a href="#Stylesheet">Stylesheet</a></li><li><a href="#Query">Query</a></li></ul></ul> </p><h1><a name="Introduction"/>Introduction<a href="#Introduction" class="section_anchor">&para;</a></h1><p>This page is an overview how XSpec test suites are compiled into XSLT and XQuery.  It shows examples of simple test suites along with their XSpec-generated stylesheets and queries. </p><p>The generated stylesheets and queries are not shown in their entirety.  In particular, the code generating parts of the final report has been removed, except in examples specifically intended to show how this is done.  The root elements of test suites are omitted, and indentation and comments have been added where appropriate. </p><p>The goal is make the compilation phase clearer, mostly for development purposes. </p><p>Those examples could be the base for test cases too (as an automated test suite, written in XSpec of course). </p><h1><a name="Simple_suite"/>Simple suite<a href="#Simple_suite" class="section_anchor">&para;</a></h1><p>Show the structure of a compiled test suite, both in XSLT and XQuery. </p><h2><a name="Test_suite"/>Test suite<a href="#Test_suite" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;t:description xmlns:t=&quot;http://www.jenitennison.com/xslt/xspec&quot;
               xmlns:q=&quot;http://example.org/ns/query&quot;
               query=&quot;http://example.org/ns/query&quot;
               stylesheet=&quot;http://example.org/ns/stylesheet.xsl&quot;&gt;

   &lt;t:scenario label=&quot;scenario&quot;&gt;
      &lt;t:call function=&quot;f&quot;/&gt;
      &lt;t:expect label=&quot;expectations&quot; test=&quot;predicate&quot;/&gt;
   &lt;/t:scenario&gt;

&lt;/t:description&gt;</pre><h2><a name="Stylesheet"/>Stylesheet<a href="#Stylesheet" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;xsl:stylesheet xmlns:test=&quot;http://www.jenitennison.com/xslt/unit-test&quot;
                xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
                xmlns:x=&quot;http://www.jenitennison.com/xslt/xspec&quot;
                xmlns:o=&quot;http://www.w3.org/1999/XSL/TransformAliasAlias&quot;
                xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
                xmlns:impl=&quot;urn:x-xspec:compile:xslt:impl&quot;
                xmlns:t=&quot;http://www.jenitennison.com/xslt/xspec&quot;
                xmlns:q=&quot;http://example.org/ns/query&quot;
                version=&quot;2.0&quot;&gt;

   &lt;!-- the tested stylesheet --&gt;
   &lt;xsl:import href=&quot;http://example.org/ns/stylesheet.xsl&quot;/&gt;
   &lt;!-- an XSPec stylesheet providing tools --&gt;
   &lt;xsl:import href=&quot;.../generate-tests-utils.xsl&quot;/&gt;

   &lt;xsl:namespace-alias stylesheet-prefix=&quot;o&quot; result-prefix=&quot;xsl&quot;/&gt;

   &lt;xsl:output name=&quot;report&quot; method=&quot;xml&quot; indent=&quot;yes&quot;/&gt;

   &lt;!-- the tested stylesheet --&gt;
   &lt;xsl:variable name=&quot;x:stylesheet-uri&quot; as=&quot;xs:string&quot;
                 select=&quot;&#x27;http://example.org/ns/stylesheet.xsl&#x27;&quot;/&gt;

   &lt;!-- the main template to run the suite --&gt;
   &lt;xsl:template name=&quot;x:main&quot;&gt;
      &lt;!-- info message --&gt;
      &lt;xsl:message&gt;
         &lt;xsl:text&gt;Testing with &lt;/xsl:text&gt;
         &lt;xsl:value-of select=&quot;system-property(&#x27;xsl:product-name&#x27;)&quot;/&gt;
         &lt;xsl:text&gt; &lt;/xsl:text&gt;
         &lt;xsl:value-of select=&quot;system-property(&#x27;xsl:product-version&#x27;)&quot;/&gt;
      &lt;/xsl:message&gt;
      &lt;!-- setup the result document (the report) --&gt;
      &lt;xsl:result-document format=&quot;report&quot;&gt;
         &lt;xsl:processing-instruction name=&quot;xml-stylesheet&quot;&gt;
            &lt;xsl:text&gt;type=&quot;text/xsl&quot; href=&quot;.../format-xspec-report.xsl&quot;&lt;/xsl:text&gt;
         &lt;/xsl:processing-instruction&gt;
         &lt;x:report stylesheet=&quot;{ $x:stylesheet-uri }&quot; date=&quot;{ current-dateTime() }&quot;&gt;
            &lt;!-- a call instruction for each top-level scenario --&gt;
            &lt;xsl:call-template name=&quot;x:d4e2&quot;/&gt;
         &lt;/x:report&gt;
      &lt;/xsl:result-document&gt;
   &lt;/xsl:template&gt;

   &lt;!-- generated from the scenario element --&gt;
   &lt;xsl:template name=&quot;x:d4e2&quot;&gt;
      ...
      &lt;!-- a call instruction for each expect element --&gt;
      &lt;xsl:call-template name=&quot;x:d4e4&quot;&gt;
         ...
      &lt;/xsl:call-template&gt;
   &lt;/xsl:template&gt;

   &lt;!-- generated from the expect element --&gt;
   &lt;xsl:template name=&quot;x:d4e4&quot;&gt;
      ...
   &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre><h2><a name="Query"/>Query<a href="#Query" class="section_anchor">&para;</a></h2><pre class="prettyprint">(: the tested library module :)
import module namespace q = &quot;http://example.org/ns/query&quot;;
(: an XSPec library module providing tools :)
import module namespace test = &quot;http://www.jenitennison.com/xslt/unit-test&quot;
  at &quot;.../generate-query-utils.xql&quot;;

declare namespace t = &quot;http://www.jenitennison.com/xslt/xspec&quot;;
declare namespace x = &quot;http://www.jenitennison.com/xslt/xspec&quot;;

(: generated from the scenario element :)
declare function local:d4e2()
{
  ...
  (: a call instruction for each expect element :)
  local:d4e4($result)
  ...
};

(: generated from the expect element :)
declare function local:d4e4($t:result as item()*)
{
  ...
};

(: the query body of this main module, to run the suite :)
(: setup the result document (the report) :)
&lt;t:report xmlns:t=&quot;http://www.jenitennison.com/xslt/xspec&quot;
          date=&quot;2010-01-28T22:45:03.649+01:00&quot;
          query=&quot;http://example.org/ns/query&quot;&gt;
{
  (: a call instruction for each top-level scenario :)
  local:d4e2()
}
&lt;/t:report&gt;</pre><h1><a name="Simple_scenario"/>Simple scenario<a href="#Simple_scenario" class="section_anchor">&para;</a></h1><p>Show the structure of a compiled scenario, both in XSLT and XQuery.  The general idea is to generate a template for the scenario (or a function in XQuery), that calls the SUT and puts the result in a variable ($x:result in XSLT and $local:result in XQuery).  A separate template (or function in XQuery) is generated for each expectation, and those templates (or functions) are called from the first one, in sequence, with the result as parameter. </p><h2><a name="Test_suite"/>Test suite<a href="#Test_suite" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;t:scenario label=&quot;scenario&quot;&gt;
   &lt;t:call function=&quot;f&quot;/&gt;
   &lt;t:expect label=&quot;expectations&quot; test=&quot;predicate&quot;/&gt;
&lt;/t:scenario&gt;</pre><h2><a name="Stylesheet"/>Stylesheet<a href="#Stylesheet" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;!-- generated from the scenario element --&gt;
&lt;xsl:template name=&quot;x:d4e2&quot;&gt;
   &lt;x:call function=&quot;f&quot;/&gt;
   &lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
      &lt;xsl:sequence select=&quot;f()&quot;/&gt;
   &lt;/xsl:variable&gt;
   ... generate scenario data in the report ...
   &lt;xsl:call-template name=&quot;x:d4e4&quot;&gt;
      &lt;xsl:with-param name=&quot;x:result&quot; select=&quot;$x:result&quot;/&gt;
   &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;

&lt;!-- generated from the expect element --&gt;
&lt;xsl:template name=&quot;x:d4e4&quot;&gt;
   &lt;xsl:param name=&quot;x:result&quot; required=&quot;yes&quot;/&gt;
   &lt;!-- expected result (none here) --&gt;
   &lt;xsl:variable name=&quot;impl:expected&quot; select=&quot;()&quot;/&gt;
   &lt;!-- wrap $t:result into a doc node if node()+ --&gt;
   &lt;xsl:variable name=&quot;impl:test-items&quot; as=&quot;item()*&quot;&gt;
      &lt;xsl:choose&gt;
         &lt;xsl:when test=&quot;$x:result instance of node()+&quot;&gt;
            &lt;xsl:document&gt;
               &lt;xsl:copy-of select=&quot;$x:result&quot;/&gt;
            &lt;/xsl:document&gt;
         &lt;/xsl:when&gt;
         &lt;xsl:otherwise&gt;
            &lt;xsl:sequence select=&quot;$x:result&quot;/&gt;
         &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
   &lt;/xsl:variable&gt;
   &lt;!-- evaluate the predicate with $t:result as context
        node if $t:result is a single node, if not just
        evaluate the predicate --&gt;
   &lt;xsl:variable name=&quot;impl:test-result&quot; as=&quot;item()*&quot;&gt;
      &lt;xsl:choose&gt;
         &lt;xsl:when test=&quot;count($impl:test-items) eq 1&quot;&gt;
            &lt;xsl:for-each select=&quot;$impl:test-items&quot;&gt;
               &lt;xsl:sequence select=&quot;predicate&quot; version=&quot;2&quot;/&gt;
            &lt;/xsl:for-each&gt;
         &lt;/xsl:when&gt;
         &lt;xsl:otherwise&gt;
            &lt;xsl:sequence select=&quot;predicate&quot; version=&quot;2&quot;/&gt;
         &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
   &lt;/xsl:variable&gt;
   &lt;!-- did the test pass? --&gt;
   &lt;xsl:variable name=&quot;impl:boolean-test&quot; as=&quot;xs:boolean&quot;
                 select=&quot;$impl:test-result instance of xs:boolean&quot;/&gt;
   &lt;xsl:variable name=&quot;impl:successful&quot; as=&quot;xs:boolean&quot; select=&quot;
       if ( $impl:boolean-test ) then
         $impl:test-result
       else
         test:deep-equal($impl:expected, $impl:test-result, 2)&quot;/&gt;
   ... generate test result in the report ...
&lt;/xsl:template&gt;</pre><h2><a name="Query"/>Query<a href="#Query" class="section_anchor">&para;</a></h2><pre class="prettyprint">(: generated from the scenario element :)
declare function local:d4e2()
{
  ... generate scenario data in the report ...
  let $local:result := f()
    return (
      local:d4e4($local:result)
    )
};

(: generated from the expect element :)
declare function local:d4e4($t:result as item()*)
{
  let $local:expected    :=                  (: expected result (none here) :)
      (  )
  let $local:test-result :=                  (: evaluate the predicate :)
      if ( $t:result instance of node() ) then
        $t:result/( predicate )
      else
        ( predicate )
  let $local:successful  :=                  (: did the test pass?:)
      if ( $local:test-result instance of xs:boolean ) then
        $local:test-result
      else
        test:deep-equal($local:expected, $local:test-result)
    return
      ... generate test result in the report ...
};</pre><h1><a name="SUT"/>SUT<a href="#SUT" class="section_anchor">&para;</a></h1><p>The SUT (or System Under Test) is the component tested in a scenario.  In XSpec, this is either an XSLT template (named or rule) or an XPath function (written either in XSLT or XQuery). Here, we use it to refer to the three ways to refer to the SUT itself, as well as parameters to use for the current scenario: <tt>apply</tt>, <tt>call</tt> and <tt>context</tt> (so that&#x27;s not strictly speacking the SUT itself, but rather the way to &quot;call&quot; it for this scenario). </p><p><tt>apply</tt> represents applying a template rule to a node (this is not possible in XQuery), and corresponds naturally to <tt>xsl:apply-templates</tt>.  <tt>call</tt> represents a call either to a named template or an XPath function.  <tt>context</tt> also represents applying a template rule to a node, but in a different way than <tt>apply</tt>: the former represents more a full transform (e.g. the result is always one document node) where <tt>apply</tt> is exactly the result of a template rule (the result is the exact result sequence or the rule). </p><p>Those examples show only what is related to the call of the SUT in the template (or function) generated from the scenario (see the section &quot;Simple scenario&quot;). </p><h2><a name="Test_suite"/>Test suite<a href="#Test_suite" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;!-- apply template rules on a node (with t:apply) --&gt;
&lt;t:variable name=&quot;ctxt&quot;&gt;
   &lt;elem/&gt;
&lt;/t:variable&gt;
&lt;t:apply select=&quot;$ctxt&quot; mode=&quot;mode&quot;&gt;
   &lt;t:param name=&quot;p1&quot; select=&quot;val1&quot; tunnel=&quot;yes&quot;/&gt;
   &lt;t:param name=&quot;p2&quot; as=&quot;element()&quot;&gt;
      &lt;val2/&gt;
   &lt;/t:param&gt;
&lt;/t:apply&gt;

&lt;!-- call a function --&gt;
&lt;t:call function=&quot;f&quot;&gt;
   &lt;t:param select=&quot;val1&quot;/&gt;
   &lt;t:param name=&quot;p2&quot; as=&quot;element()&quot;&gt;
      &lt;val2/&gt;
   &lt;/t:param&gt;
&lt;/t:call&gt;

&lt;!-- call a named template --&gt;
&lt;t:call template=&quot;t&quot;&gt;
   &lt;t:param name=&quot;p1&quot; select=&quot;val&quot;/&gt;
   &lt;t:param name=&quot;p2&quot;&gt;
      &lt;val2/&gt;
   &lt;/t:param&gt;
&lt;/t:call&gt;

&lt;!-- apply template rules on a node (with t:context) --&gt;
&lt;t:context&gt;
   &lt;elem/&gt;
&lt;/t:context&gt;</pre><h2><a name="Stylesheet"/>Stylesheet<a href="#Stylesheet" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;xsl:variable name=&quot;ctxt&quot; as=&quot;item()*&quot;&gt;
   &lt;elem/&gt;
&lt;/xsl:variable&gt;
&lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
   &lt;xsl:variable name=&quot;p1&quot; select=&quot;val1&quot;/&gt;
   &lt;xsl:variable name=&quot;p2&quot; as=&quot;element()&quot;&gt;
      &lt;val2/&gt;
   &lt;/xsl:variable&gt;
   ... error if &quot;$ctxt instance of node()&quot; is not true ...
   &lt;xsl:apply-templates select=&quot;$ctxt&quot; mode=&quot;mode&quot;&gt;
      &lt;xsl:with-param name=&quot;p1&quot; select=&quot;$p1&quot; tunnel=&quot;yes&quot;/&gt;
      &lt;xsl:with-param name=&quot;p2&quot; select=&quot;$p2&quot;/&gt;
   &lt;/xsl:apply-templates&gt;
&lt;/xsl:variable&gt;

&lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
   &lt;xsl:variable name=&quot;...&quot; select=&quot;val&quot;/&gt;
   &lt;xsl:variable name=&quot;p2&quot; as=&quot;element()&quot;&gt;
      &lt;val2/&gt;
   &lt;/xsl:with-param&gt;
   &lt;xsl:sequence select=&quot;f($..., $p2)&quot;/&gt;
&lt;/xsl:variable&gt;

&lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
   &lt;xsl:variable name=&quot;p1&quot; select=&quot;val&quot;/&gt;
   &lt;xsl:variable name=&quot;p2&quot; as=&quot;item()*&quot;&gt;
      &lt;val2/&gt;
   &lt;/xsl:with-param&gt;
   &lt;xsl:call-template name=&quot;t&quot;&gt;
      &lt;xsl:with-param name=&quot;p1&quot; select=&quot;$p1&quot;/&gt;
      &lt;xsl:with-param name=&quot;p2&quot; select=&quot;$p2&quot;/&gt;
   &lt;/xsl:call-template&gt;
&lt;/xsl:variable&gt;

&lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
   &lt;xsl:variable name=&quot;context-doc&quot; as=&quot;document-node()&quot;&gt;
      &lt;xsl:document&gt;
         &lt;elem/&gt;
      &lt;/xsl:document&gt;
   &lt;/xsl:variable&gt;
   &lt;xsl:variable name=&quot;context&quot; select=&quot;$context-doc/node()&quot;/&gt;
   &lt;xsl:apply-templates select=&quot;$context&quot;/&gt;
&lt;/xsl:variable&gt;</pre><h2><a name="Query"/>Query<a href="#Query" class="section_anchor">&para;</a></h2><pre class="prettyprint">TODO: ...</pre><h1><a name="Variables"/>Variables<a href="#Variables" class="section_anchor">&para;</a></h1><p>This is not implemented yet, but this is an example of what they will look like. </p><h2><a name="Test_suite"/>Test suite<a href="#Test_suite" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;t:scenario label=&quot;scenario&quot;&gt;
   &lt;t:variable name=&quot;var&quot; select=&quot;&#x27;value&#x27;&quot;/&gt;
   ...
   &lt;t:expect .../&gt;
&lt;/t:scenario&gt;</pre><h2><a name="Stylesheet"/>Stylesheet<a href="#Stylesheet" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;!-- generated from the scenario element --&gt;
&lt;xsl:template name=&quot;x:d4e2&quot;&gt;
   &lt;!-- the generated variable --&gt;
   &lt;xsl:variable name=&quot;var&quot; select=&quot;&#x27;value&#x27;&quot;/&gt;
   &lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
      ... evaluate the test expression ...
   &lt;/xsl:variable&gt;
   ...
   &lt;xsl:call-template name=&quot;x:d4e4&quot;&gt;
      &lt;xsl:with-param name=&quot;x:result&quot; select=&quot;$x:result&quot;/&gt;
   &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;

&lt;!-- generated from the expect element --&gt;
&lt;xsl:template name=&quot;x:d4e4&quot;&gt;
   &lt;xsl:param name=&quot;x:result&quot; required=&quot;yes&quot;/&gt;
   &lt;!-- the generated variable --&gt;
   &lt;xsl:variable name=&quot;var&quot; select=&quot;&#x27;value&#x27;&quot;/&gt;
   &lt;!-- evaluate the expectation --&gt;
   &lt;xsl:variable name=&quot;impl:expected&quot; ...&gt;
   &lt;xsl:variable name=&quot;impl:test-items&quot; ...&gt;
   &lt;xsl:variable name=&quot;impl:test-result&quot; ...&gt;
   ...
&lt;/xsl:template&gt;</pre><h2><a name="Query"/>Query<a href="#Query" class="section_anchor">&para;</a></h2><pre class="prettyprint">(: generated from the scenario element :)
declare function local:d4e2()
{
  ...
  let $var          := &#x27;value&#x27;               (: the generated variable :)
  let $local:result := ... evaluate the test expression ...
    return (
      local:d4e4($local:result)
    )
};

(: generated from the expect element :)
declare function local:d4e4($t:result as item()*)
{
  let $var               := &#x27;value&#x27;          (: the generated variable :)
  let $local:expected    := ...              (: expected result :)
  let $local:test-result := ...              (: evaluate the expectations :)
  let $local:successful  := ...              (: did the test pass?:)
    return
      ... generate test result in the report ...
};</pre><h1><a name="Variable_value"/>Variable value<a href="#Variable_value" class="section_anchor">&para;</a></h1><p>Here is an example of three variables, one using <tt>@select</tt>, one using content, and one using <tt>@href</tt>.  As with <tt>xsl:variable</tt>, they must use one and exactly one of these attributes.  The href attribute is to load a document from a file (relative to the test suite document).  The resulting variables must appear once in the code generated for the <tt>scenario</tt> element and once in the code generated for the <tt>expect</tt> element (well, define more precisely the scope of the variables, I think we should be able to put them everywhere, and the scope must &quot;natural&quot; when looking at the test suite definition). </p><h2><a name="Test_suite"/>Test suite<a href="#Test_suite" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;t:variable name=&quot;select&quot;  select=&quot;&#x27;value&#x27;&quot;/&gt;
&lt;t:variable name=&quot;href&quot;    href=&quot;test-data.xml&quot;/&gt;
&lt;t:variable name=&quot;content&quot; as=&quot;element()&quot;&gt;
   &lt;elem/&gt;
&lt;/t:variable&gt;</pre><h2><a name="Stylesheet"/>Stylesheet<a href="#Stylesheet" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;xsl:variable name=&quot;select&quot; select=&quot;&#x27;value&#x27;&quot;/&gt;
&lt;xsl:variable name=&quot;href&quot;   select=&quot;doc(&#x27;.../test-data.xml&#x27;)&quot;/&gt;
&lt;xsl:variable name=&quot;content&quot; as=&quot;element()&quot;&gt;
   &lt;elem/&gt;
&lt;/xsl:variable&gt;</pre><h2><a name="Query"/>Query<a href="#Query" class="section_anchor">&para;</a></h2><pre class="prettyprint">let $select := &#x27;value&#x27;
let $href   := doc(&#x27;.../test-data.xml&#x27;)
let $content as element() := &lt;elem/&gt;</pre><h1><a name="Variables_scope"/>Variables scope<a href="#Variables_scope" class="section_anchor">&para;</a></h1><p>This shows where variables are generated regarding their scope. It is worth noting the first definition of this was to generate variables several times if needed, e.g. if they were in scope in a scenario and expectations (see the revision <a href="/p/xspec/source/detail?r=78">r78</a> of this page for an example).  But this would lead to several evaluations of the same thing (which could lead to being less efficient, and to subtle bugs in case of side-effects). So instead, variables are evaluated once, then passed as parameters (to templates in XSLT and functions in XQuery). </p><h2><a name="Test_suite"/>Test suite<a href="#Test_suite" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;t:variable name=&quot;global&quot; ...&gt;
&lt;t:scenario label=&quot;outer&quot;&gt;
   &lt;t:variable name=&quot;var-1&quot; ...&gt;
   &lt;t:scenario label=&quot;inner&quot;&gt;
      &lt;t:variable name=&quot;var-2&quot; ...&gt;
      &lt;t:call function=&quot;f&quot;/&gt;
      &lt;t:variable name=&quot;var-3&quot; ...&gt;
      &lt;t:expect label=&quot;expect one&quot; ...&gt;
      &lt;t:variable name=&quot;var-4&quot; ...&gt;
      &lt;t:expect label=&quot;expect two&quot; ...&gt;
   &lt;/t:scenario&gt;
&lt;/t:scenario&gt;</pre><h2><a name="Stylesheet"/>Stylesheet<a href="#Stylesheet" class="section_anchor">&para;</a></h2><pre class="prettyprint">&lt;xsl:variable name=&quot;global&quot; ...&gt;

&lt;!-- generated from the scenario outer --&gt;
&lt;xsl:template name=&quot;x:d4e2&quot;&gt;
   &lt;!-- the generated variable --&gt;
   &lt;xsl:variable name=&quot;var-1&quot; ...&gt;
   ...
   &lt;xsl:call-template name=&quot;x:d4e3&quot;&gt;
      &lt;!-- pass the variable to inner context --&gt;
      &lt;xsl:with-param name=&quot;var-1&quot; select=&quot;$var-1&quot;/&gt;
   &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;

&lt;!-- generated from the scenario inner --&gt;
&lt;xsl:template name=&quot;x:d4e3&quot;&gt;
   &lt;!-- the variable is passed as param --&gt;
   &lt;xsl:param name=&quot;var-1&quot; required=&quot;yes&quot; ...&gt;
   &lt;!-- the generated variable --&gt;
   &lt;xsl:variable name=&quot;var-2&quot; ...&gt;
   &lt;xsl:variable name=&quot;x:result&quot; as=&quot;item()*&quot;&gt;
      &lt;xsl:sequence select=&quot;f()&quot;/&gt;
   &lt;/xsl:variable&gt;
   ...
   &lt;!-- the generated variable --&gt;
   &lt;xsl:variable name=&quot;var-3&quot; ...&gt;
   &lt;xsl:call-template name=&quot;x:d4e4&quot;&gt;
      &lt;xsl:with-param name=&quot;x:result&quot; select=&quot;$x:result&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-1&quot;    select=&quot;$var-1&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-2&quot;    select=&quot;$var-2&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-3&quot;    select=&quot;$var-3&quot;/&gt;
   &lt;/xsl:call-template&gt;
   &lt;!-- the generated variable --&gt;
   &lt;xsl:variable name=&quot;var-4&quot; ...&gt;
   &lt;xsl:call-template name=&quot;x:d4e5&quot;&gt;
      &lt;xsl:with-param name=&quot;x:result&quot; select=&quot;$x:result&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-1&quot;    select=&quot;$var-1&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-2&quot;    select=&quot;$var-2&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-3&quot;    select=&quot;$var-3&quot;/&gt;
      &lt;xsl:with-param name=&quot;var-4&quot;    select=&quot;$var-4&quot;/&gt;
   &lt;/xsl:call-template&gt;
&lt;/xsl:template&gt;

&lt;!-- generated from the expect one --&gt;
&lt;xsl:template name=&quot;x:d4e4&quot;&gt;
   &lt;xsl:param name=&quot;x:result&quot; required=&quot;yes&quot;/&gt;
   &lt;!-- the variables are passed as param --&gt;
   &lt;xsl:param name=&quot;var-1&quot; required=&quot;yes&quot; ...&gt;
   &lt;xsl:param name=&quot;var-2&quot; required=&quot;yes&quot; ...&gt;
   &lt;xsl:param name=&quot;var-3&quot; required=&quot;yes&quot; ...&gt;
   ... evaluate the expectations ...
&lt;/xsl:template&gt;

&lt;!-- generated from the expect two --&gt;
&lt;xsl:template name=&quot;x:d4e5&quot;&gt;
   &lt;xsl:param name=&quot;x:result&quot; required=&quot;yes&quot;/&gt;
   &lt;!-- the variables are passed as param --&gt;
   &lt;xsl:param name=&quot;var-1&quot; required=&quot;yes&quot; ...&gt;
   &lt;xsl:param name=&quot;var-2&quot; required=&quot;yes&quot; ...&gt;
   &lt;xsl:param name=&quot;var-3&quot; required=&quot;yes&quot; ...&gt;
   &lt;xsl:param name=&quot;var-4&quot; required=&quot;yes&quot; ...&gt;
   ... evaluate the expectations ...
&lt;/xsl:template&gt;</pre><h2><a name="Query"/>Query<a href="#Query" class="section_anchor">&para;</a></h2><pre class="prettyprint">declare variable $global := ...;

(: generated from the scenario outer :)
declare function local:d4e2()
{
  ...
  let $var-1 := ...
  ...
    return (
      local:d4e3($var-1)
    )
};

(: generated from the scenario inner :)
declare function local:d4e3($var-1) (: $var-1 can have a &quot;as&quot; clause :)
{
  ...
  let $var-2        := ...
  let $local:result := f()
    return (
      let $var-3 := ...
        return (
          local:d4e4($local:result, $var-1, $var-2, $var-3),
          let $var-4 := ...
            return (
              local:d4e5($local:result, $var-1, $var-2, $var-3, $var-4)
            )
        )
    )
};

(: generated from the expect one :)
declare function local:d4e4($t:result as item()*, $var-1, $var-2, $var-3)
{
  ...evaluate the expectations ...
};

(: generated from the expect two :)
declare function local:d4e5($t:result as item()*, $var-1, $var-2, $var-3, $var-4)
{
  ...evaluate the expectations ...
};</pre>
 </td> 
 </tr>
 </table>
 </div>


 
 
 
 
 
 <div id="commentform">
 <form action="../w/detail.do" method="post">
 <table>
 <tr><td class="vt">
 <input type="hidden" name="pagename" value="Compilation" >
 <input type="hidden" name="token" value="55b122417e72b952b1b3411d91b5d902" >
 <div>Enter a comment:</div>
 <textarea name="content" rows="6" cols="80"></textarea><br><br>
 <input type="submit" name="submit" value="Submit" >
 </td>
 <td class="vt">
 <div id="whb" class="tip" style="width:15em">
 <div class="round4"></div>
 <div class="round2"></div>
 <div class="round1"></div>
 <div class="box-inner closed"
 id="entrybubble">
 <a class="ifClosed" href="#whb" style="float:right"
 onclick="_toggleHidden(this); document.getElementById('wikihelp').value='opened'">show</a>
 <a class="ifOpened" href="#whb" style="float:right"
 onclick="_toggleHidden(this); document.getElementById('wikihelp').value='closed'"
 >hide</a>
 <b>Wiki markup help</b>
 <div class="ifOpened">
 <div style="padding:2px; font-size:96%">
 =Heading1=<br>
 ==Heading2==<br>
 ===Heading3===<br>
 <br>
 *bold* &nbsp; &nbsp;
 _italic_<br>
 `inline code`<br>
 escape: `*`<br>
 <br>
 Indent lists 2 spaces:<br>
 &nbsp;&nbsp;* bullet item<br>
 &nbsp;&nbsp;# numbered list<br>
 <br>
 {{{<br>
 verbatim code block<br>
 }}}<br>
 <br>
 Horizontal rule<br>
 ----
 <br>
 <br>
 WikiWordLink<br>
 [http://domain/page&nbsp;label]<br>
 http://domain/page<br>
 <br>
 || table || cells ||<br>
 
 </div><br>
 <a href="http://code.google.com/p/support/wiki/WikiSyntax" target="new">More
 examples</a>
 <a href="http://code.google.com/p/support/wiki/WikiSyntax" target="new"><img
 src="http://www.gstatic.com/codesite/ph/images/tearoff_icon.gif" width="16" height="16"/></a>
 </div>
 </div>
 <div class="round1"></div>
 <div class="round2"></div>
 <div class="round4"></div>
</div>
<input type="hidden" name="wikihelp" id="wikihelp" value="closed" >

 </td></tr>
 </table>
 </form>
 </div>
 
 
 

<form name="delcom" action="../w/delComment.do" method="POST">
 <input type="hidden" name="sequence_num" value="" >
 <input type="hidden" name="create_time" value="" >
 <input type="hidden" name="mode" value="" >
 <input type="hidden" name="pagename" value="Compilation" >
 <input type="hidden" name="token" value="55b122417e72b952b1b3411d91b5d902" >
</form>



 <script src="http://www.gstatic.com/codesite/ph/14756227129406843427/js/prettify/prettify.js"></script>
 <script type="text/javascript">
 prettyPrint();
 </script>

<script type="text/javascript" src="http://www.gstatic.com/codesite/ph/14756227129406843427/js/dit_scripts.js"></script>



  
 
 <script type="text/javascript" src="http://www.gstatic.com/codesite/ph/14756227129406843427/js/core_scripts_20081103.js"></script>
 <script type="text/javascript" src="/js/codesite_product_dictionary_ph.pack.04102009.js"></script>
 </div>
<div id="footer" dir="ltr">
 
 <div class="text">
 
 &copy;2010 Google -
 <a href="/projecthosting/terms.html">Terms</a> -
 <a href="http://www.google.com/privacy.html">Privacy</a> -
 <a href="/p/support/">Project Hosting Help</a>
 
 </div>
</div>

 <div class="hostedBy" style="margin-top: -20px;">
 <span style="vertical-align: top;">Powered by <a href="http://code.google.com/projecthosting/">Google Project Hosting</a></span>
 </div>
 
 


 
 </body>
</html>


